package com.xjtu.mybatisplus.model.esdocument;

import com.xjtu.mybatisplus.model.domain.Article;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Transient;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.util.List;
import java.util.Map;

@Data
@Document(indexName = "articles")
public class ESArticle {
    @Id
    private String id; // 将映射到Elasticsearch的 _id 字段

    @Field(type = FieldType.Text, analyzer = "ik_smart")
    private String title;

    @Field(type = FieldType.Text, analyzer = "ik_smart")
    private String content;

    @Transient
    private Map<String, List<String>> highlightFields;

    public static ESArticle fromArticle(Article article) {
        ESArticle esArticle = new ESArticle();
        esArticle.setId(article.getId().toString());
        esArticle.setTitle(article.getTitle());
        esArticle.setContent(article.getPlainText());
        return esArticle;
    }
}
